package cn.schoolwow.quickdao.module.database.dql.response.flow.update;

import cn.schoolwow.quickdao.domain.QuickDAOConfig;
import cn.schoolwow.quickdao.module.database.dql.parent.domain.QueryContext;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;

public class SQLiteUpdateStatementFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        QuickDAOConfig quickDAOConfig = flowContext.checkInstanceData(QuickDAOConfig.class);
        QueryContext queryContext = (QueryContext) flowContext.checkData("queryContext");

        StringBuilder sqlBuilder = new StringBuilder();
        if(!queryContext.join.isEmpty()){
            throw new IllegalArgumentException("SQLite数据库不支持update语句进行表连接操作!");
        }
        sqlBuilder.append("update " + quickDAOConfig.databaseContext.databaseProvider.escape(queryContext.queryOption.queryTableOption.entity.tableName) + " ");
        sqlBuilder.append(queryContext.set);
        sqlBuilder.append(queryContext.noAliasNameWhere);
        flowContext.putTemporaryData("sql", sqlBuilder.toString());
    }

    @Override
    public String name() {
        return "SQLite数据库更新语句";
    }
}
